package com.gz.controller;

import java.util.List;

import com.gz.common.AftersaleXService;
import com.gz.common.model.Aftersale;
import com.gz.common.model.OrderProduct;
import com.gz.common.model.Product;
import com.gz.utils.Response;
import com.jfinal.core.Controller;

public class AftersaleXController extends Controller{
	
	/**
	 *	根据手机号码或者时间区间查询售后记录信息
	 *	@param mobile 手机号码	可传可不传
	 *	@param createtime 最小时间	可传可不传
	 *	@param endtime 最大时间	可传可不传
	 *	@url http://localhost:8081/cms-admin/afterX/findAftersaleByUserOrtime?mobile=
	 */
	public void findAftersaleByUserOrtime() {
		List<Aftersale> aftersaleList = AftersaleXService.getService().
				findAftersaleByUserOrtime(getPara("mobile"), getPara("createtime"), getPara("endtime"));
		if(aftersaleList==null) {
			renderJson(Response.responseJson(1007,"没有售后信息"));
			return;
		}
		renderJson(Response.responseJson(1008,"查询成功！",aftersaleList));
	}
	
	/**
	 * @author ZhangZhanyi
	 * 根据售后编号修改处理状态
	 * @param afterid 售后编号
	 * @param confirm 处理状态，0待处理，1同意，2，拒绝
	 * @param opinion 处理内容
	 * http://localhost:8081/cms-admin/afterX/MvAftersaleConfirm
	 */
	public void MvAftersaleConfirm() {
		Integer afterid=getParaToInt("afterid");
		Integer confirm=getParaToInt("confirm");
		String  opinion=getPara("opinion");
		//根据id查询售后对象
		Aftersale as=AftersaleXService.getService().findAftersaleById(afterid);
		if (as!=null) {
			if (confirm==1) {
				as.setConfirm(confirm);
				as.update();
				renderJson(Response.responseJson(1001,"修改成功",true));
			}else if(confirm==2){
				as.setConfirm(confirm);
				as.setOpinion(opinion);
				as.update();
				renderJson(Response.responseJson(1001,"修改成功",true));
			}

		}else {
			renderJson(Response.responseJson(1002,"修改失败",false));
		}
	}
	
	/**
	 *	根据用户和时间区间查询售出所有商品的成本总金额
	 * @param xiao	最小时间
	 * @param da	最大时间
	 * @param userName	用户名
	 * @return {"msg":"查询成功","code":1008,"data":[{"zongjine":18.0,"createTime":"2019-05-05 10:37:08","name":"asd","mobile":null,"tuihouliang":0,"xiaoshouliang":6,"username":"test"}]}
	 * @URl http://localhost:8081/cms-admin/afterX/findProductByUserId
	 */
	public void findProductByUserId() {
		List<Product> proList = AftersaleXService.getService().findProductByUserId(getPara("userName"),getPara("xiao"), getPara("da"));
		renderJson(Response.responseJson(1008,"查询成功",proList));
	}
	
	/**
	 * 查询所有用户商品销售量和成本总金额
	 * @param xiao
	 * @param da
	 * @return {"msg":"查询成功","code":1008,"data":[{"zongjine":18.0,"zongxiaoliang":6,"username":"test"}]}
	 * @Url http://localhost:8081/cms-admin/afterX/findOrderProductAll
	 */
	public void findOrderProductAll() {
		List<OrderProduct> opList=AftersaleXService.getService().findOrderProductAll(getPara("xiao"), getPara("da"));
		renderJson(Response.responseJson(1008,"查询成功",opList));
	}
}
